package com.bobo.model;

import java.awt.*;
import java.util.LinkedList;

/**
 * @author bobobo
 * @version 1.0
 * @date 2019/9/3 23:34
 */
public class MonteCarloPIData {
    private Circle circle;  //数据
    private int insideCircle = 0;
    private LinkedList<Point> points;

    public MonteCarloPIData(Circle circle){
        this.circle = circle;
        points = new LinkedList<>();
    }

    public Circle getCircle(){
        return circle;
    }

    public int getPointsNumber(){
        return points.size();
    }

    public Point getPoint(int i){
        if(i < 0 || i >= points.size())
            throw new IllegalArgumentException("out of bound in getPoint!");

        return points.get(i);
    }

    public void addPoint(Point p){
        points.add(p);
        if(circle.contain(p))
            insideCircle ++;
    }

    public double getPI(){

        if(points.size() == 0)
            return 0.0;

        int circleArea = insideCircle;
        int squareArea = points.size();
        return (double)circleArea * 4 / squareArea;
    }
}
